#pragma once
#include <string>
#include "vix.h"

namespace VirtualOps { namespace Vix { 

    namespace Utils
    {
        static void MarshalString (System::String^ s, std::string& os)
        {
           using namespace System::Runtime::InteropServices;
           const char* chars = 
              (const char*)(Marshal::StringToHGlobalAnsi(s)).ToPointer();
           os = chars;
           Marshal::FreeHGlobal(IntPtr((void*)chars));
        }
        
        /** Trade-in extra copying for nice usage syntax */
        static std::string MarshalString ( System::String^ s)
        {
           using namespace System::Runtime::InteropServices;
           const char* chars = 
              (const char*)(Marshal::StringToHGlobalAnsi(s)).ToPointer();
           std::string res = chars;
           Marshal::FreeHGlobal(IntPtr((void*)chars));
           return res;
        }

        static void ThrowVirtualOpsException(VixError err)
        {
            const char* errText = Vix_GetErrorText(err, 0); 
            String^ message = gcnew String(errText);
            throw gcnew VirtualOps::Base::VirtualOpsException(message);
        }

    }
} } // namespace VirtualOps::Vix

